<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>fetch-get-电影介绍</title>
    <script src="../vue2.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul, li {
            list-style: none;
        }

        .header {
            width: 100%;
            height: 50px;
            background-color: #fff;
            display: flex;
            position: fixed;
            top: 0;
            box-shadow: 0 1px 5px #d2d2d2;
            z-index: 999;
        }

        .header div {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;

        }

        .header div span {
            cursor: pointer;
            line-height: 45px;
        }

        .header div span.active {
            color: #ff8432;
            border-bottom: 2px solid #ff8432;
        }

        .body {
            padding-left: 15px;
            color: #4d4d4d;
            margin-top: 50px;
        }

        .body li .box-list {
            width: 100%;
            height: 190px;
            padding: 20px 0;
            box-sizing: border-box;
            display: flex;
        }

        .body .box-list img {
            width: 105px;
            height: 150px;
            border-radius: 3px;
        }

        .body .box-list .formal {
            flex: 1;
            display: flex;
            justify-content: space-between;
            /*border: 1px solid red;*/
        }

        .body .box-list .info {
            margin-left: 10px;
            padding: 15px 0;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .body .box-list .info .title span {
            font-size: 12px;
            line-height: 12px;
            color: #fff;
            padding: 0 2px;
            background-color: #d3d3d3;
            border-radius: 3px;
        }

        .body .box-list .info .grade {
            color: #ff8432;
        }

        .body .box-list .info .nation-runtime {
            display: flex;
            align-items: center;
        }

        .body .box-list .btn {
            width: 100px;
            position: relative;
            /*border: 1px solid red;*/
        }

        .body .box-list button {
            font-size: 12px;
            padding: 3px 12px;
            color: #ff8432;
            background-color: #fff;
            border: 1px solid #ff8432;
            border-radius: 2px;
            outline: none;
            position: absolute;
            top: 50%;
            right: 15px;
            transform: translateY(-50%);
            z-index: 0;
        }

        .body li .part {
            width: 100%;
            height: 1px;
            background-color: #c9c9c9;
        }
    </style>
</head>
<body>
<div id="box">
    <div class="header">
        <div>
            <span class="active" @click="handleFetch">正在热映</span>
        </div>
        <div>
            <span>即将上映</span>
        </div>
    </div>

    <div class="body">
        <ul>
            <li v-for="item in datalist" :key="item.filmId">
                <div class="box-list">
                    <img :src="item.poster" alt="">
                    <div class="formal">
                        <div class="info">
                            <div class="title">
                                {{ item.name }}&nbsp
                                <span>{{ item.item.name }}</span>
                            </div>
                            <span>
                                {{ item.grade ? '观众评分&nbsp' : '' }}<span
                                    class="grade">{{ item.grade ? item.grade : ''}}</span>
                            </span>
                            <span>
                                主演：{{ item.actorsStr}}
                            </span>
                            <span class="nation-runtime">
                                {{ item.nation }}&nbsp
                                |&nbsp
                                {{ item.runtime }}分钟
                            </span>
                        </div>
                        <div class="btn">
                            <button>购票</button>
                        </div>
                    </div>
                </div>
                <div class="part"></div>
            </li>
        </ul>
    </div>
</div>
<script>
    new Vue({
        el: "#box",
        data: {
            datalist: [],
            actorsList: []
        },
        created() {
            this.handleFetch()
        },
        methods: {
            handleFetch() {
                fetch("./json/maizuo.json")
                    .then(res => res.json())
                    .then(res => {
                        console.log(res.data)
                        for (let i = 0; i < res.data.films.length; i++) {
                            let actors = '';
                            let film = res.data.films[i];

                            film.actors.forEach(item => {
                                actors += item.name + ' ';
                            })
                            film.actorsStr = actors;
                        }
                        this.datalist = res.data.films;
                        console.log(res.data.films)
                    })
                    .catch(() => {
                        console.log('error')
                    })
            }
        },
        watch: {}
    })
</script>
</body>
</html>